package Convert_stream_package;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class Convert_stream_demo1 {
    public static void main(String[] args) throws IOException {
        /*
            利用转换流按照指定字符编码读取
         */

        //1、创建对象并指定字符编码
        InputStreamReader isr = new InputStreamReader(new FileInputStream("/Users/zhaoxiaoyong/Documents/" +
                "Java/IO_stream_project/Convert_stream_module/src/rough_draft/a.txt"), "GBK");
        //2、读取数据
        int ch;
        while ((ch = isr.read()) != -1) {
            System.out.print((char) ch);
        }
        //3、释放资源
        isr.close();
        System.out.println();


        //JDK11的新方式：
        FileReader fr = new FileReader("/Users/zhaoxiaoyong/Documents/Java/IO_stream_project/" +
                "Convert_stream_module/src/rough_draft/a.txt", Charset.forName("GBK"));
        //2、读取数据
        while ((ch = fr.read()) != -1) {
            System.out.print((char) ch);
        }
        //3、释放资源
        fr.close();
    }
}
